package com.zhonghui.scm.controller;

import com.zhonghui.common.core.controller.BaseController;
import com.zhonghui.common.core.page.TableDataInfo;
import com.zhonghui.common.utils.poi.ExcelUtil;
import com.zhonghui.response.BaseResult;
import com.zhonghui.scm.domain.ScmPurchaseArrival;
import com.zhonghui.scm.service.IScmPurchaseArrivalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购到货Controller
 * 
 * @author zhonghui
 * @date 2022-05-26
 */
@Api(tags="供应链SCM-采购管理-采购到货")
@RestController
@RequestMapping("/scm/purchase/arrival")
public class ScmPurchaseArrivalController extends BaseController
{
    @Autowired
    private IScmPurchaseArrivalService scmPurchaseArrivalService;

    /**
     * 查询采购到货列表
     */
    @ApiOperation("采购管理-采购到货列表")
    @GetMapping("/list")
    public TableDataInfo<List<ScmPurchaseArrival>> getList(ScmPurchaseArrival scmPurchaseArrival)
    {
        startPage();
        List<ScmPurchaseArrival> list = scmPurchaseArrivalService.getList(scmPurchaseArrival);
        return getDataTable(list);
    }

    /**
     * 导出采购到货列表
     */
    @ApiOperation("导出采购管理-采购到货列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmPurchaseArrival scmPurchaseArrival)
    {
        List<ScmPurchaseArrival> list = scmPurchaseArrivalService.getList(scmPurchaseArrival);
        ExcelUtil<ScmPurchaseArrival> util = new ExcelUtil<ScmPurchaseArrival>(ScmPurchaseArrival.class);
        util.exportExcel(response, list, "采购到货数据");
    }

    /**
     * 获取采购到货详细信息
     */
    @ApiOperation("采购管理-采购到货详细信息")
    @GetMapping(value = "/{id}")
    public BaseResult<ScmPurchaseArrival> getById(@PathVariable("id") Long id)
    {
        return BaseResult.success(scmPurchaseArrivalService.getById(id));
    }

    /**
     * 新增采购到货
     */
    @ApiOperation("新增采购管理-采购到货")
    @PostMapping
    public BaseResult<Integer> add(@RequestBody ScmPurchaseArrival scmPurchaseArrival)
    {
        return BaseResult.success(scmPurchaseArrivalService.add(scmPurchaseArrival));
    }

    /**
     * 修改采购到货
     */
    @ApiOperation("修改采购管理-采购到货")
    @PutMapping
    public BaseResult<Integer> edit(@RequestBody ScmPurchaseArrival scmPurchaseArrival)
    {
        return BaseResult.success(scmPurchaseArrivalService.edit(scmPurchaseArrival));
    }

    /**
     * 删除采购到货
     */
    @ApiOperation("删除采购管理-采购到货")
	@DeleteMapping("/{ids}")
    public BaseResult<Integer> remove(@PathVariable Long[] ids)
    {
        return BaseResult.success(scmPurchaseArrivalService.del(ids));
    }
}
